postgresql how to work with aggregate functions

join shbcf.ru